<template>
    <van-nav-bar
        title="购物车"
        left-text="返回"
        left-arrow
        @click-left="onClickLeft"
    />
    <van-divider :style="{ color: '#ee0a24', borderColor: '#1989fa', padding: '0 16px' }">
    </van-divider>
    <div class="order-confirm">
        <van-row v-for="car of checkedCarList">
            <van-col span="6">
                <van-image
                        height="60px"
                        width="60px"
                        fit="fill"
                        :src="car.foodMainImage"
                />
            </van-col>
            <van-col span="10">
                <div class="name">{{ car.foodName }}</div>
                <div class="price">￥{{car.foodPrice}}</div>
            </van-col>
            <van-col span="6" class="count-wrapper">
                <span class="count">{{ car.quantity }}</span>
            </van-col>
        </van-row>

        <van-address-list
            v-model="chosenAddressId"
            :list="deliveryAddressList"
            default-tag-text="默认"
            @add="onAdd"
        />

        <van-button type="primary" block @click="runInto">提交订单</van-button>
    </div>
</template>

<script>
import {showDialog} from "vant";

export default {
    name: "confirm",
    data(){
        return{
            checkedCarList:[],
            chosenAddressId:'1',
            deliveryAddressList:[]
        }
    },methods:{
        _initDeliveryAddressList(){
            this.$axios.get('/ele_server/order/deliveryAddressList').then(({ data:res })=>{
                if(res.status == 0){
                    for(let item of res.data) {
                        this.deliveryAddressList.push({
                            id: item.id,
                            name:item.contactName,
                            tel:item.phone,
                            address: item.address
                        })
                    }
                    this.deliveryAddressList[0].isDefault=true;
                }else if(res.status == 3003){
                    showDialog({
                        title: '提示',
                        message: '当前未登录',
                        theme: 'round-button',
                        confirmButtonText:'去登录'
                    }).then(() => {
                        this.$router.push('/user/login?redirect=/order/confirm');
                    });
                }else{

                }
            })

        },
        onAdd(){
            this.$router.push('/address/addressAdd')
        },
        onClickLeft(){
          this.$router.back()
        },
        runInto(){
            this.$router.push('/user/my');
        }

    },
    created() {
       this.checkedCarList=JSON.parse(localStorage.getItem('setCheckedCarList'))
        this._initDeliveryAddressList();
    }
}
</script>

<style scoped lang="stylus">
 .order-confirm
   >>>.van-address-list
       .van-address-list
           position relative

</style>
